import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		userName: {},
		token:'',
		isFirstLogin: true,   // 是否为第一次登录
		userIdentity: {}    // 用户角色A
	},
	mutations: {
		// 登录
		LOGIN(state, provider) {
			// provider = {
			//	token: res.data.token,
			//	data: res.data.data
			//	}
			state.userName = provider.data,
			state.token = provider.token
		},
		// 登出
		LOGOUT(state, provider) {
			state.userName = ''
			uni.clearStorage()
		},
		// 设置userName
		SET_USERNAME(state, provider) {
			state.userName = provider
		},
		// 设置isFirstLogin
		SET_FIRSTLOGIN(state, provider){
			state.isFirstLogin = provider
		},
		// 设置用户角色
		SET_IDENTITY(state, provider) {
			state.userIdentity = provider
		}
	}
})

export default store